package codeRandomThoughts.Test55跳跃游戏;

class Solution2 {
    public boolean canJump(int[] nums) {
        //只有一个元素,不用跳就是终点
        if (nums.length==1){
            return true;
        }

        //覆盖范围
        int coverRange = 0;

        //在覆盖范围内遍历,看能否扩大覆盖范围
        for (int i = 0; i <= coverRange; i++) {
            coverRange = Math.max(coverRange,i+nums[i]);
            if (coverRange>= nums.length-1){
                return true;
            }
        }
        return false;
    }

}